package com.bussiness.system.config;

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.plugins.PerformanceInterceptor;
import com.baomidou.mybatisplus.spring.MybatisMapperRefresh;
import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * 
 * @author : xlr
 * @date : 2018/08/13
 */
@EnableTransactionManagement
@Configuration
@MapperScan("com.bussiness.system.dao")
public class MybatisPlusConfig {
    /**
     *   mybatis-plus分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        page.setDialectType("mysql");
        return page;
    }

    /**
     * mybatis-plus SQL执行效率插件【生产环境可以关闭】
     */
    @Bean
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }

//
//    @Bean
//    @Qualifier("sqlSessionFactory")
//    public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean(@Qualifier("dataSource") DataSource dataSource){
//        MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        mybatisSqlSessionFactoryBean.setDataSource( dataSource );
//        return mybatisSqlSessionFactoryBean;
//    }
//
//    @Bean
//    public MybatisMapperRefresh mybatisMapperRefresh(@Qualifier("sqlSessionFactory")SqlSessionFactory sqlSessionFactory){
//        MybatisMapperRefresh mapperRefresh = new MybatisMapperRefresh( null,sqlSessionFactory,true );
//        return mapperRefresh;
//    }
}
